/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hanuma;

import java.util.*;

/**
 *
 * @author niyaz
 */
public class Filling {

    public static void run() {

        int found = 0;
        Persistent right = new PersistentInBase("mright");
        Persistent all = new PersistentInBase("mall");

        Queue<String> queue = new LinkedList<String>();
        VKontakteApi vk = new VKontakteApi(Conf.token, Conf.id);
        queue.add("10000");
        while (true) {

            if (queue.isEmpty()) {
                System.out.println("No any user");
                System.exit(0);
            }
            String current = queue.poll();
            //  System.out.println(current);
          //  while (all.contains(current)) {
              //  if (queue.isEmpty()) {
              //      System.out.println("No any user");
              //      System.exit(0);
             //   }
             //   current = queue.poll();
         //   }

            //   System.out.println(current);

            try {


                if (queue.size() < 10000) {
                    List<String> friends = vk.getFriends(current);
                    for (String friend : friends) {
                        if ((queue.size() < 12000) && (!all.contains(friend))) {
                            queue.add(friend);
                        }

                    }
                }

                int grad = vk.getGraduation(current);
                int city = vk.getCity(current);
                //int sex = vk.getSex(current);
                // System.out.println(current + " "+grad+" "+city+ " "+vk.getLastName(current)+" "+vk.getSex(current));

                if ((city == 2) && (grad <= 2015) && (grad >= 2012)) {
                    System.out.println("found " + (++found) + " " + current + " " + all.size() + " " + vk.getLastName(current));
                    right.put(current);
                }
                all.put(current);
            } catch (Exception e) {
                if (!e.toString().contains(new String("educ")) && !e.toString().contains(new String("java.lang.NullPointerException"))) {
                    System.out.println(e);
                    System.out.println(current);
                    e.printStackTrace();
                    break;
                }
            }
        }

    }
}
